export const CookieUtil = {
    setCookie(key, value, expireDays) {
        const date = new Date()
        date.setTime(date.getTime() + (expireDays * 24 * 60 * 60 * 1000))
        const expires = "expires=" + date.toUTCString()
        const cookieStr = `${key}=${value};${expires};path=/;SameSite=Strict`
        document.cookie = cookieStr
        console.log('Setting cookie:', cookieStr)
    },
  
    getCookie(key) {
        const name = key + "="
        const decodedCookie = decodeURIComponent(document.cookie)
        const cookieArray = decodedCookie.split(';')
        for (let i = 0; i < cookieArray.length; i++) {
            let cookie = cookieArray[i]
            while (cookie.charAt(0) === ' ') {
                cookie = cookie.substring(1)
            }
            if (cookie.indexOf(name) === 0) {
                const cookies = cookie.substring(name.length, cookie.length)
                console.log('Current cookies:', cookies)
                return cookies
            }
        }
        return null
    },
  
    removeCookie(key) {
        document.cookie = `${key}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;SameSite=Strict`
    }
  }
  
  export default CookieUtil